#!/bin/bash

set -e

USAGE="Usage: $0"

chmod 777 bashphant.sh;
chmod 777 getpkg.sh;
chmod 777 installDefaultpkgs.sh;
./bashphant.sh;

echo "Adding ROS repository...";
sh -c 'echo "deb http://packages.ros.org/ros/ubuntu precise main" > /etc/apt/sources.list.d/ros-latest.list';
echo "ROS repository successfully added!";
echo "Retrieving and adding key...";
wget http://packages.ros.org/ros.key -O - | apt-key add -;
echo "Key successfully added!";
echo "Updating repository index..."
apt-get update;
echo "Done!";
echo "Installing ROS Desktop Full...";
apt-get install ros-fuerte-desktop-full;
echo "Done!";
echo "Retrieving ROS...";
apt-get install python-rosinstall python-rosdep;
echo "Done!";
echo "Installing ROS...";
rosinstall ~/ros /opt/ros/fuerte;
echo "source ~/ros/setup.bash" >> ~/.bashrc;
echo 'export ROS_PACKAGE_PATH=~/ros:$ROS_PACKAGE_PATH' >> ~/.bashrc;
source ~/.bashrc;
echo "Done!";
echo "Retrieving SVN data...";
cd ~/ros;
svn co https://svn.3me.tudelft.nl/dbl-ros-pkg/trunk dbl-ros-pkg-dev
echo "Done!";
echo "Setting up keyring, please provide your NetID and Password for SVN...";
svn info https://svn.3me.tudelft.nl/BME-BMechE/DBL;
echo "Done!";
cd -
echo "Setting up rosdep...";
rosdep init;
rosdep update;
echo "Installing packages...";
rosinstall ~/ros ./phidgetspp.rosinstall;
chmod -R 777 ~/ros;
./bashphant.sh;
echo "All done! Please run ./installDefaultpkgs.sh";
